# leetcode 232 用栈模拟队列


class MyQueue:

    def __init__(self):
        self.in_stack = []
        self.out_stack = []


    def push(self, x: int) -> None:
        self.in_stack.append(x)


    def pop(self) -> int:
        if not (self.in_stack or self.out_stack):
            return
        elif self.out_stack:
            return self.out_stack.pop()
        else:
            while self.in_stack:
                self.out_stack.append(self.in_stack.pop())
            return self.out_stack.pop()


    def peek(self) -> int:
        if not (self.in_stack or self.out_stack):
            return
        elif self.out_stack:
            tmp = self.out_stack.pop()
            self.out_stack.append(tmp)
            return tmp
        else:
            while self.in_stack:
                self.out_stack.append(self.in_stack.pop())
            tmp = self.out_stack.pop()
            self.out_stack.append(tmp)
            return tmp       


    def empty(self) -> bool:
        if not (self.in_stack or self.out_stack):
            return True
        return False


# Your MyQueue object will be instantiated and called as such:
# obj = MyQueue()
# obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.peek()
# param_4 = obj.empty()
